package 正则;

import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class RegexTest {

	public static void main(String[] args) {
//		test2();
		String message = "1317836./u89qy468767868";
		String message1 = "ca";
		char[] chars = message.toCharArray();
		StringBuilder sb = new StringBuilder();//线程不安全
		for (char c : chars) {
			if (c < '0' || c > '9') {
				break;
			}
			sb.append(c);
		}
		System.out.println(sb.toString());
		
		System.out.println("**********************");
		Pattern p = Pattern.compile("\\d*");
		Matcher matcher = p.matcher(message);
//		while (matcher.find()) {
//			String group = matcher.group();
//			System.out.println(group);
//		}
		if (matcher.find()) {
			String g = matcher.group();
			System.out.println("message :"+ g);
		}
		
		
		String aa = "CA000457316580./223236";
		String bb = aa.substring(2);
		String cc = aa.substring(0,2);
		System.out.println(bb);
		System.out.println(cc);
				
	}

	private static void test2() {
		//		String aa = "123_nihao";
		//		aa = aa.replaceAll("_", "`_");
		//		System.out.println(aa);
		//		
		//		String bb = "ni13andoe13ando";
		//		String[] split = bb.split("\\d");
		//		for (int i = 0; i < split.length; i++) {
		//			System.out.println(split[i]);
		//		}

		//		String cc = "ca123789./nadbo";
		//		System.out.println(cc.substring(2));
		//		cc = cc.substring(0, 2)+cc.substring(2).replaceAll("\\D", "");
		//		System.out.println(cc);
		String ff = "000457316580./223236";
		int indexOf = ff.indexOf("//D");
		System.out.println(indexOf);


		//		String dd = "";
		//		String ee = "CA000457316580./223236";
		//		String test1 = test1(ee);
		//		System.out.println(test1);
	}

	private static String test1(String id) {
		if ((!id.isEmpty()) && id.length() >=2) {
			id = id.substring(0, 2)+id.substring(2).replaceAll("\\D", "");
			return id;
		} else {
			return id;
		}
	}

}
